package com.googlecode.microanalyst.palette.edit;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.AccessibleEditPart;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.swt.accessibility.AccessibleControlEvent;
import org.eclipse.swt.accessibility.AccessibleEvent;

import com.googlecode.microanalyst.designer.edit.AnalysisConnectionEditPolicy;
import com.googlecode.microanalyst.designer.edit.AnalysisConnectionEndpointEditPolicy;
import com.googlecode.microanalyst.designer.edit.AnalysisEditPart;
import com.googlecode.microanalyst.palette.figure.LabeledConnectionFigure;
import com.googlecode.microanalyst.palette.i18n.PaletteMessages;
import com.googlecode.microanalyst.palette.model.LabeledConnection;

public class LabeledConnectionEditor extends AnalysisEditPart implements
		EditPart {

	public LabeledConnectionEditor() {
	}

	@Override
	protected AccessibleEditPart createAccessible() {
		return new AccessibleGraphicalEditPart() {
			public void getValue(AccessibleControlEvent e) {
				e.result = getLabeledConnection().getLabel();
			}

			public void getName(AccessibleEvent e) {
				e.result = PaletteMessages.Palette_Tool_LabeledConnection;
			}
		};
	}

	protected LabeledConnection getLabeledConnection() {
		return (LabeledConnection) getModel();
	}

	@Override
	protected IFigure createFigure() {
		return new LabeledConnectionFigure();
	}

	protected void createEditPolicies() {
		super.createEditPolicies();
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE,
				new LabeledConnectionDirectEditPolicy());
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new LabeledConnectionEditPolicy());
		installEditPolicy(EditPolicy.CONNECTION_ROLE,
				new AnalysisConnectionEditPolicy());
		installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE,
				new AnalysisConnectionEndpointEditPolicy());
	}

}
